<%--
  Created by IntelliJ IDEA.
  User: 86150
  Date: 2021/10/28
  Time: 19:46
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>销售报表</title>
    <link type="text/css" rel="stylesheet" href="fontsawesome/css/font-awesome.css"/>
    <link type="text/css" rel="stylesheet" href="css/datepicker.css"/>
    <link type="text/css" rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="main_box">
    <h2><span></span>销售报表</h2>
    <form action="${pageContext.request.contextPath}/AS1" method="post">
        <div class="search_box clearfix">
            <label class="f_left">开始日期：</label>
            <div class="date_box">
                <input type="text" name="regtime" id="start_date" readonly/>
                <i class="fa fa-calendar"></i>
            </div>
            <label class="f_left">结束日期：</label>
            <div class="date_box">
                <input type="text" name="regtime1" id="end_date" readonly/>
                <i class="fa fa-calendar"></i>
            </div>
            <input type="submit" value="搜索" class="btn blue_btn"/>

<%--            <input type="button" value="导出销售报表" class="btn btn_info">--%>
        </div>
    </form>
    <div class="cont_box" style="border-top:1px dashed #ddd;">

        <p class="business_tit">财务报表</p>
        <table border="0" cellspacing="0" cellpadding="0" class="table business_table" id="table_box2">
            <input type="submit"  onclick="exportExcel('table_box2')" value="导出销售报表" class="btn btn_info"/>
<%--        <input type="submit"  onclick="exportExcel('table_box2')" value="导出销售报表" class="btn btn_info"/>--%>
<%--        <table border="0" cellspacing="0" cellpadding="0" class="table" id="table_box2">--%>
            <thead>
            <tr>
                <c:forEach items="${cill}" var="cill">
                    <th>${cill.zhifu}</th>
                </c:forEach>
                <th>总计</th>


            </tr>
            </thead>
            <tbody>
            <tr>
<c:forEach items="${cill}" var="cill">
                <td>${cill.moneysum}</td>
</c:forEach>
                <td>${bills}</td>
            </tr>
            </tbody>
        </table>
        <p class="business_tit">业务报表</p>
        <table border="0" cellspacing="0" cellpadding="0" class="table">
            <thead>
            <tr>
                <th>车辆台次</th>
                <th>储值卡</th>
                <th>年卡</th>
                <th>会员消费</th>
                <th>售后收入</th>
                <th>会员维修收入</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>${findcar}</td>
                <td>${findchu}</td>
                <td>${findnian}</td>
                <td>${findmoney}</td>
                <td>${findsh}</td>

                <td><span class="table_link see_nocard" title="点击查看详情">800.00</span></td>
            </tr>
            </tbody>
        </table>
        <p class="business_tit">商品销售报表</p>
        <table border="0" cellspacing="0" cellpadding="0" class="table">
            <thead>
            <tr>
                <th>商品名称</th>
                <th>数量</th>
                <th>金额</th>
            </tr>
            </thead>
            <tbody>
<c:forEach items="${findc}" var="findc">
            <tr>
                <td>${findc.pname}</td>
                <td>${findc.cname}</td>
                <td>${findc.moneysums}</td>
            </tr>
</c:forEach>
            </tbody>
        </table>
        <p class="business_tit">商品库存报表</p>
        <table border="0" cellspacing="0" cellpadding="0" class="table">
            <thead>
            <tr>
                <th>商品名称</th>
                <th>期初库存数</th>
                <th>当前库存数</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${findproductall}" var="findproductall">
                <td>${findproductall.pname}</td>
                <td>${findproductall.stockc}</td>
                <td>${findproductall.stock}</td>
            </tr>
            </c:forEach>
            <tr>
            </tbody>
        </table>
    </div>
</div>
<!--javascript include-->
<script src="js/jquery-2.2.1.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script src="js/other.js"></script>
<script>
    $(function(){
        //=====弹出窗设置
        function DelTipWidth(Twidth,Theight){
            $(".tip_box",Wparent).css({"width":Twidth+"px","height":Theight+"px","margin-top":-(Theight/2)+"px","margin-left":-(Twidth/2)+"px"});
            $(".tip_close",Wparent).on("click",Tipclose);
        }
        //=====关闭弹出窗
        function Tipclose(){
            $(".tip_box",Wparent).remove(); //移除新增的外层className
            $(".tip_bg",Wparent).remove(); //移除新增的背景className
        }
        //初始化
        var Wparent = window.parent.document,
            tipBg = "<div class='tip_bg'></div>",
            tipBox = "<div class='tip_box'></div>";
        function tipW(headTxt,linkHref){
            $("body",Wparent).append(tipBg);
            $("body",Wparent).append(tipBox);
            $(".tip_box",Wparent).prepend("<h2>"+headTxt+"<span class='tip_close'><i class='fa fa-close'></i></span></h2><div class='tip_tbox'></div>");
            $(".tip_tbox",Wparent).append("<iframe src='"+linkHref+"' frameborder='0' width='100%' height='100%' seamless></iframe>");
            DelTipWidth(800,520);
            var titH = $(".tip_box",Wparent).find("h2").outerHeight();
            $(".tip_tbox",Wparent).css("height",520 - titH);
        }
        //非卡类型
        $(".see_nocard").click(function(){
            var index = $(this.parentNode).prevAll().length,
                pTxt = $(this).parents("table").prev().text(),
                headTxt = pTxt+" - "+$(this).parents("tbody").prev().find("th").eq(index).text(),
                linkHref = "report_Nocard.html";
            tipW(headTxt,linkHref);
        });
        //卡类型
        $(".see_card").click(function(){
            var index = $(this.parentNode).prevAll().length,
                pTxt = $(this).parents("table").prev().text(),
                headTxt = pTxt+" - "+$(this).parents("tbody").prev().find("th").eq(index).text(),
                linkHref = "report_Card.html";
            tipW(headTxt,linkHref);
        });
        //商品销售报表
        $(".see_goods").click(function(){
            var headTxt = "商品销售报表",
                linkHref = "report_GoodsSale.html";
            tipW(headTxt,linkHref);
        });
    });
    var idTmr;
    //获取当前浏览器类型
    function getExplorer() {
        var explorer = window.navigator.userAgent ;
        //ie
        if (explorer.indexOf("MSIE") >= 0) {
            return 'ie';
        }
        //firefox
        else if (explorer.indexOf("Firefox") >= 0) {
            return 'Firefox';
        }
        //Chrome
        else if(explorer.indexOf("Chrome") >= 0){
            return 'Chrome';
        }
        //Opera
        else if(explorer.indexOf("Opera") >= 0){
            return 'Opera';
        }
        //Safari
        else if(explorer.indexOf("Safari") >= 0){
            return 'Safari';
        }
    }

    //获取到类型需要判断当前浏览器需要调用的方法，目前项目中火狐，谷歌，360没有问题
    //win10自带的IE无法导出
    function exportExcel(tableid) {
        if(getExplorer()=='ie')
        {
            var curTbl = document.getElementById(tableid);
            var oXL = new ActiveXObject("Excel.Application");
            var oWB = oXL.Workbooks.Add();
            var xlsheet = oWB.Worksheets(1);
            var sel = document.body.createTextRange();
            sel.moveToElementText(curTbl);
            sel.select();
            sel.execCommand("Copy");
            xlsheet.Paste();
            oXL.Visible = true;

            try {
                var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
            } catch (e) {
                print("Nested catch caught " + e);
            } finally {
                oWB.SaveAs(fname);
                oWB.Close(savechanges = false);
                oXL.Quit();
                oXL = null;
                idTmr = window.setInterval("Cleanup();", 1);
            }

        }
        else
        {
            tableToExcel(tableid)
        }
    }
    function Cleanup() {
        window.clearInterval(idTmr);
        CollectGarbage();
    }

    //判断浏览器后调用的方法，把table的id传入即可
    var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html><head><meta charset="UTF-8"></head><body><table>{table}</table></body></html>',
            base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },
            format = function(s, c) {
                return s.replace(/{(\w+)}/g,
                    function(m, p) { return c[p]; }) }
        return function(table, name) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
            window.location.href = uri + base64(format(template, ctx))
        }
    })()
</script>
</body>
</html>

